﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.SystemManager;
using CubicFWNet.Data.ViewModal;

namespace CubicFWNet.Application.SystemManager
{
    public class ArapApp
    {
        private ArapRepository _service = new ArapRepository();
        private FinanceNumRepository _financeNumRepositoryservice = new FinanceNumRepository();

        public int Add(Arap web)
        {
            return _service.Insert(web);
        }

        public int Update(Arap web)
        {
            return _service.Update(web);
        }

        public List<Arap> GetListArapByName(string financeNumber)
        {
            return _service.IQueryable(a => a.FinanceNumber == financeNumber).ToList();
        }
        public Arap GetSingleByFinanceNumber(string financeNumber)
        {
            return _service.FindEntity(a => a.FinanceNumber == financeNumber);
        }
        public Arap GetSingle(Guid id)
        {
            return _service.FindEntity(a => a.Id == id);
        }

        public Arap GetSingleBack(Guid id)
        {
            return _service.FindEntity(a => a.FinanceInvoiceId == id);
        }

        public ArapView GetSingleArapView(Guid id)
        {
            return _service.GetSingleArapView(id);
        }

        public IEnumerable<ArapView> GetListArapViews(int type, int status, string financeNumber, string customerName)
        {
            return _service.GetListArapViews(type, status, financeNumber, customerName).OrderBy(a => a.Status).ThenByDescending(a => a.InvoiceType).ThenByDescending(a => a.ApplyTime);
        }

        public IEnumerable<ArapView> GetListArapYingfuViews(int type, int status, string customerName, string financeNumber)
        {
            return _service.GetListArapYingfuViews(type, status, customerName, financeNumber).OrderBy(a => a.Status).ThenBy(a => a.FinanceNumber);
        }

        public int GetCountFinanceNum(string financeNum)
        {
            return _financeNumRepositoryservice.IQueryable(a => a.FinanceNumber == financeNum).Count();
        }

        public int InsertFinanceNum(FinanceNum web)
        {
            return _financeNumRepositoryservice.Insert(web);
        }
    }
}
